<?php

class Model {
	private $_ColumnId;
	private $_Id;
	private $_Table;
	private $_Active;
	private $_Description;
	private $_OrderBy;

	public function __construct($arrInitialValues = null){
		FunctionsHelper::includeFiles(
			array(
				PUBLIC_HELPERS_DIRECTORY . 'dbFunction.php'
			)
		);

		if (isset($arrInitialValues['id']) && !empty($arrInitialValues['id']))
			$this->setId($arrInitialValues['id']);		
		else
			$this->setId(0);

		if (isset($arrInitialValues['active']) && !empty($arrInitialValues['active']))
			$this->setActive($arrInitialValues['active']);
		else
			$this->setActive(0);
			
		if (isset($arrInitialValues['description']) && !empty($arrInitialValues['description']))
			$this->setDescription($arrInitialValues['description']);
		else
			$this->setDescription('');
			
		if (isset($arrInitialValues['order_by']) && !empty($arrInitialValues['order_by']))
			$this->setOrderBy($arrInitialValues['order_by']);
		else
			$this->setOrderBy($this->getColumnId());
			
		if (isset($arrInitialValues[$this->getColumnId()]) && !empty($arrInitialValues[$this->getColumnId()]))
			$this->setId($arrInitialValues[$this->getColumnId()]);
	}


	public function setOrderBy($value){
		$this->_OrderBy = $value;
	}

	public function getOrderBy(){
		return $this->_OrderBy;
	}
	
	public function setDescription($value){
		$this->_Description = $value;
	}

	public function getDescription(){
		return $this->_Description;
	}

	public function setColumnId($value){
		$this->_ColumnId = $value;
	}

	public function getColumnId(){
		return $this->_ColumnId;
	}

	public function setId($value){
		$this->_Id = $value;
	}

	public function getId(){
		return $this->_Id;
	}
	
	public function setTable($value){
		$this->_Table = $value;
	}
	
	public function getTable(){
		return $this->_Table;
	}
	
	public function setActive($value){
		$this->_Active = $value;
	}
	
	public function getActive(){
		return $this->_Active;
	}
	
	
	public function getOne(){
		$query = '
			SELECT *
			FROM ' . $this->getTable() . '
			WHERE ' . $this->getColumnId() . ' = ' . $this->getId();

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}
	
	public function getAll(){
		$query = '
			SELECT *
			FROM ' . $this->getTable();

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}
	
}

?>